package com.liujie.dhunting.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liujie.dhunting.entity.Customer;
import com.liujie.dhunting.entity.User;
import com.liujie.dhunting.mapper.CustomerMapper;
import com.liujie.dhunting.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Resource
    CustomerMapper customerMapper;

    @PostMapping("/test")
    public Result<?> test(@RequestBody Customer customer){
        customer.setCustomerid("111");
        customer.setType("222");
        customer.setScope("333");
        customer.setPosition("444");
        customer.setLastinfo("555");
        customerMapper.insert(customer);
        return Result.success();
    }
    @GetMapping("/find")
    public Result<?> findPage(@RequestParam(defaultValue = "1") Integer pageNumber,
                              @RequestParam(defaultValue = "10") Integer pageSize,
                              @RequestParam(defaultValue = "") String keyWords){
        LambdaQueryWrapper<Customer> wrapper= Wrappers.<Customer>lambdaQuery();
        if(StrUtil.isNotBlank(keyWords)){
            wrapper.like(Customer::getCustomername,keyWords).or()
                    .like(Customer::getType,keyWords).or()
                    .like(Customer::getPosition,keyWords).or()
                    .eq(Customer::getScope,keyWords);
        }
        Page<Customer> customerPage = customerMapper.selectPage(new Page<Customer>(pageNumber,pageSize), wrapper);
        return Result.success(customerPage);
    }
}
